package drg_group.beijing_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.beijing_2022.Base;
import drg_group.beijing_2022.MedicalRecord;
import drg_group.beijing_2022.ADRG.*;

public class MDCS{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"B39.500","B08.100","A50.401","J10.800x002","A20.700","B76.100","B67.401","B34.400x001","A41.501","A79.800x002","B53.100","B48.201","A18.206","B65.001","B51.000","A49.902","B34.100","A52.700x001","A28.001","A75.000x004","B04.x00","A66.200","B26.800x004","B25.900x002","A95.900","B85.100","A23.900x006","A49.800x003","A59.900","A02.900x004","A18.813+D77*","A53.900","T81.403","A43.100","A96.200","A23.900x001","A02.000","B05.800x008","A26.800x001","A51.301","A54.808","A31.901","A68.000","B37.801","B69.800x003","B60.800x001","B08.000x004","A02.101","A30.900x003","B01.800x002+N08.0*","A27.900x006","B70.100","B34.400","B49.x00x021","B74.000x003","T98.200x012","B67.600x002","B85.000","B03.x00x002","A01.300","A54.809","A28.200","B74.902","B03.x00","A42.800x002","A31.803","A42.804","B99.x00x001","B45.700","A20.800x005","A49.815","A92.000","B46.900x002","A30.400x001","B18.904+N08.0*","T82.700x005","A01.000x012","A79.801","A49.100x006","A24.201","A66.300","A93.801","B99.x01","A50.000","A02.000x010","A30.300x002","A20.300","A98.300","B55.200","B48.401","B74.900","B34.400x002","A92.200","B02.900x002","B55.000","A24.100x003","B42.800","A75.300x001","A18.207","B27.001","B42.100x003","A23.100","B46.100x001+G99.8*","B33.800","B66.100","B66.800x003","A56.001","A50.400x001","A51.400x001","A93.200","B55.100x001","B26.804","A52.100x011","A36.800x005+N33.8*","A41.503","A36.900x002","B26.900x001","A28.100","B68.900x002","A31.800x002","B05.800x010","T82.700x010","B47.100","B74.200x001","A49.002","A55.x00","B46.400","B08.000x002","A40.100","B66.800x006","B69.805","A44.100","A18.208","A56.200","A98.400x001","B08.800x006","B74.400x003","B90.102+N29.1*","A50.100","B81.100","A38.x00x011","A48.100x001","B46.800x001","B87.100","B85.300","B47.100x001","A22.700","A27.900x004","B02.900x001","A26.700x001","B33.000x001","A50.500x001","B69.800x008","A49.900","B66.200","B40.700","B42.900","A75.100","B55.000x001","B45.900","A23.300","B81.000","A06.800x001","A21.800x001","B60.000x001","B74.400","A49.001","B08.200","T80.200","T85.711","A41.400x001","A49.103","A02.000x007","T85.712","A60.001","A67.100","A01.000x011","A02.900x002","B83.900","B37.700","B74.900x005","R50.900x002","A51.001","B69.900x001","B88.800x004","A19.100","A26.900","A30.100x003","T82.700x001","A98.200","B67.904","A49.000","A19.900x004","A06.002","B38.700","T85.700x104","B55.000x003","B26.800x011","A01.200","A41.500x083","B44.100x003","A56.000x003","T82.700x004","A02.901","A19.901","A02.100x002","A01.000x014","B48.400","A20.101","A63.800","A49.004","A98.800","B08.400x003","T85.701","A41.904+N16.0*","A96.800","A01.100","A49.300","B83.300","A06.100","B01.900x002","A24.102","A41.000","A92.100","B00.900x005","A30.200","A48.200","B05.802","A31.800x001","A49.800x015","A40.903+N16.0*","A69.800","A31.800x007","A20.802","B01.800x004","A95.100","A49.810","A06.800x003","B50.801","A18.200x006","A49.805","B44.700","A75.000x002","B41.800x001","P37.100","A31.100x002","B66.902","A49.806","A99.x00","B43.900","A18.209","B87.300","A42.700","B36.800","A24.400","T81.401","A32.803","A48.800x002","B65.000x001","B68.901","B08.200x002","A01.000x009","A21.300","P37.000","A41.900","B43.801","B71.100","B74.000x001","A19.902","B39.900","B48.000","A23.000","B74.800x001","B39.400","B81.200","A30.900x004","B26.800x010","B47.900","A92.300x002","A56.300x001","B74.100x001","A22.000","A41.500x087","A18.101","A18.212","A38.x00x012","B27.900x001","B67.902","A49.301","A26.700","A51.100x001","B65.900x007","T81.406","A54.600x001","B66.300","A31.000x001","B67.907","B65.300","B47.000","B65.900x006","A52.300","A02.800","B74.200x003","B83.800x007","A23.903+N16.0*","A22.100x003","B88.900x002","A66.700","R50.901","A01.000x018","A30.200x001","A49.102","A67.900","A27.800","B71.000","B73.x00","A77.000x001","R50.900","A51.300x002","B05.901","B83.800x002","B69.801","B34.101","B88.000x002","B88.300","A30.000x001","A30.500x001","B69.802","A41.505","T85.700x103","B57.500","A30.900x002","R50.800x002","A40.200","B50.000","B83.800x004","A51.900","B41.800x003","B48.000x001","A06.000","B74.100x003","A94.x01","A48.801","A31.102","B37.808","A31.900x001","T81.402","A96.000","A98.400","B64.x00","A67.300","A52.900","B83.800x008","A56.800","A52.101","A59.000","B44.802","B56.100x001","A06.100x002","B00.204","B77.800x004","A93.100","A21.000","B51.900","A66.600","T81.404","A97.200","T82.700x007","A41.805","A26.000","B88.200x001","B67.903","A49.200","B65.905+N08.0*","A77.300","B80.x00","B66.800x001","B68.900x003","T81.400x005","B41.700","B51.800","A48.100x003","B71.900","B66.300x001","A28.000","A56.302","A20.801","A50.900","A23.200","B66.800x007","B53.800x001","B74.300","A24.002","B49.x18","A21.800","A97.100","B44.900x001","A48.300","B02.800x001","B55.200x001","A51.201","B74.000x002","A30.300","B66.900","A02.000x006","A01.000x019","B58.900x001","R50.803","T81.400x004","B40.900","B79.x00","A77.100x001","A54.100x002","B66.101","B74.901","B77.800x002","A92.300","A63.002","T82.700x008","A77.900x001","A06.200","R68.801","A31.000","A92.400","A23.900x003","A41.800x002","B83.000x001","A49.807","B05.801","T98.200x021","A06.001","T80.200x004","B48.300","B75.x00","A18.806+E35.0*","B08.401","A18.200x010","A77.300x001","B02.900x003","B83.800x003","A20.803","B88.100","A31.000x005","A63.000","A01.003","A51.300x003","B08.000x001","A92.300x004","A49.800x019","A42.801","B33.100","A43.801","A44.800","A20.900x002","B37.800x085","B57.200x001","B08.300","B76.902","B05.900x005","A52.801","A38.x00","A54.601","B37.400x001+N37.0*","T82.700x003","B00.205","B34.800x002","B05.900x001","A27.000","B18.103+N08.0*","B55.100","B85.200","A28.900","T85.706","A78.x00","B66.000x001","A52.100","A23.900x004","A58.x00","B58.801+N16.0*","B66.500","A77.200","B44.800x005","A77.800","A24.202","A42.900","A57.x00x002","A51.303","A51.002","B65.800x002","T81.400x006","B67.301","A18.211","A49.101","A40.800","B37.700x001","B05.900x002","B39.300","A68.900","A52.700x012+N08.0*","A21.301","A30.900","B87.800x001","A22.200x001","A65.x00","B44.800x003","A41.100x002","A98.000","A66.900","A31.800x004","B53.000x001","A30.300x001","B54.x00x008","B43.100","A21.100","B40.800","A64.x00","A49.817","B77.900","A69.200","A43.900","A41.804","B83.800x009","A31.801","A23.000x001","A42.200x002","A31.001","B66.400","B05.800x009","T82.701","B67.901","B67.601","A51.200","B65.800x001","A97.000","A01.400","B00.700","A35.x00x001","A53.000x002","B34.000","T82.700x011","A42.802","A18.105+N29.1*","B00.901","A38.x00x013","A49.801","A41.900x004","A92.300x001","B66.800x002","A49.800x023","B54.x00x004","B69.800x004","T85.708","A01.000x008","A92.001","A27.900x005","B49.x00x007","A06.200x001","A49.811","B48.200","B74.400x002","A67.200","B88.900x001","A42.000","B56.900x001","T82.700x009","A06.800x002","A48.400","A30.400","A75.200x001","B00.701","T82.700x002","A51.302","A31.000x004","A66.800","A96.100","B27.800","A44.900","B67.600x001","A56.301","A69.900","A18.103+N29.1*","B56.000x001","B69.803","T86.807","A30.400x002","A02.001","A20.000x001","B51.000x001+D77*","B76.000","B08.801","B78.700","A92.300x003","A18.104+N29.1*","A49.812","B33.300x001","B83.800x006","O98.600x001","T88.000","A79.100","A01.000x010","A48.100","B57.300","A77.900","A40.000","A24.001","A42.805","B83.201","B38.900","T80.201","B45.801","B78.901","A32.900","B34.102","A21.700","B77.803","A30.100x001","A49.813","B83.800x005","B87.900","A41.803","B39.400x001","A41.101","B83.100","A97.900","T85.700x808","B67.906","A92.900","B37.802","A18.100x022+N37.8*","A31.802","A18.700x002+E35.1*","A02.000x009","A30.900x008","B34.800x004","B26.805+N08.0*","A98.100","A98.500x001+N08.0*","T85.710","A02.000x005","A79.900","B66.901","A18.106+N29.1*","A79.000","B50.900x001","A01.000x020","A66.000","A43.802","A54.900x001","B48.402","A38.x00x010","A30.800","B76.900x003","B45.800x002","A49.800x014","A93.000","B69.804","A96.100x001","B65.200x001","A41.807","A63.001","B36.801","B42.700","A36.804+N16.0*","A18.100x031","A28.801","A41.806","B81.800x002","T84.701","A79.901","A31.100","A51.000x002","B60.000","A54.900x002","B33.801","A77.200x001","B66.800x005","B89.x01","B65.900x008","A02.100","B03.x00x003","A60.900","B00.001","A06.300x001","B41.900","A42.100","B50.800","B88.000x003","B37.800x088","P37.300","A02.900x003","B18.205+N08.0*","B25.900x001","A01.000x004","A49.804","A21.700x002","B06.900x001","A18.100x025+N29.1*","A50.600","A41.300","B67.302+E35.0*","A24.000x002","A20.000","A24.000","B89.x00","T85.700x809","A22.900","A21.900x001","A30.500","B46.800x002","B74.200x002","B66.400x001","A01.000x007","B67.700x001","B33.000","B39.500x001","A38.x00x014","A27.800x001","A01.000x017","A48.800","T81.400x002","B27.000","A51.500","B49.x11","A25.000x001","A66.400","A31.800x003","B26.800x008+N08.0*","A52.709+N08.0*","A95.000","B38.800","B81.801","A49.100x005","B77.800x005","A18.210","A49.800x020","A27.900x002","A02.004","B67.905","A67.000","A41.802","A06.900","A51.304","A30.900x005","A49.802","A54.001","A59.001+N37.0*","B00.202","A51.300x004","A58.x01","A23.800","A63.003","A49.100x004","A44.000","A52.200","A01.000","A19.900","A41.200","B74.400x001","B66.000","A60.002","A56.400","B05.400","B78.902+N08.0*","B57.100","B08.800x004","B76.901","A92.800","A40.900","A41.400","A25.900","B76.800","B52.900x001","A36.900","B83.400","B42.100x002","A20.200","A40.300","B83.800x001","B48.800x001","B67.400x001","A42.803","A41.506","A49.808","B65.800x003","B81.400","T85.703","T81.405","B65.100x001","A18.801+E35.8*","A23.100x001","B81.300","B74.900x003","B66.800x004","B81.802","A19.900x005","A32.700","B57.200x003","Z03.000","B33.802","B01.801","A66.100","B34.200","B46.500","A18.100x021+N37.8*","A01.000x006","B42.100","A26.900x002","A22.200","A25.100x001","B34.300x002","B45.100","B05.803","A68.100","A70.x00","A75.000x003","A50.500","A77.100","B07.x00x009","B52.001+N08.0*","B78.000","A18.108+N33.0*","A18.107+N29.1*","A54.900","B68.000","A02.002","A49.814","A75.001","B69.800x005","B70.000","B67.600x003","A21.300x002","A02.003","B03.x00x004","A31.800x005","A24.101","A20.100","A48.000","B65.101","R50.802","A43.800x001","A18.800x001","B52.800","A54.602","A50.700","A31.101","A50.400","B88.800x002","A50.200","B81.800x001","B52.000x002+N08.0*","A93.802","B01.900x001","T85.709","B25.800x001","A51.300x005","B48.700","B88.800x001","A59.800x001","B34.900","B52.000","B27.100","A18.700+E35.1*","A51.000","A49.901","A31.800x006","B48.300x001","B69.100","B71.800","A57.x00x003","B34.800x003","T85.702","A53.000x001","A77.000","B34.801","B42.100x001","B74.100x002","B83.000","A32.701","A42.200","T79.300x001","B49.x00x013","A06.000x001","A74.900","B83.200x003","R50.801","A51.400x010","A31.002","A52.800","A49.003","A32.000","B68.900x004","B02.700","A41.801","B00.900x007","A19.200","B85.400","B55.900","A20.800x004","A75.900","A06.700","A49.803","A54.002","B37.901","B88.900x003","B44.801","A41.504","A24.100x002","A19.200x001","B00.902","B83.200x001","A96.900","T81.400x001","B37.900","A92.500","B68.100","A41.502","B37.401+N37.0*","B49.x02+E35.8*","A06.300","A54.500","B54.x00x006","A49.201","B43.800","B76.900","B83.000x002","B34.300","A24.300"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCS入组条件，匹配规则：主诊断匹配");
        String result;

        result=SB1.group(record);
        if (result.length()>0){
            return result;
        }

        if (false && record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合SQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "SQY";
        }

        result=SR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ST1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SU1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SV1.group(record);
        if (result.length()>0){
            return result;
        }

        result=SZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCS的ADRG入组条件");
        return "";
    }
}

